home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / show / show.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-15  |  10.9 KB  |  288 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BackColor       =   &H00000000&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Boom!"
  6.    ClientHeight    =   3615
  7.    ClientLeft      =   150
  8.    ClientTop       =   720
  9.    ClientWidth     =   5055
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   3615
  14.    ScaleWidth      =   5055
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.Label Label1 
  17.       BackStyle       =   0  'Transparent
  18.       ForeColor       =   &H8000000E&
  19.       Height          =   255
  20.       Left            =   0
  21.       TabIndex        =   0
  22.       Top             =   0
  23.       Width           =   855
  24.    End
  25.    Begin VB.Menu File 
  26.       Caption         =   "&File"
  27.       Index           =   1
  28.       WindowList      =   -1  'True
  29.       Begin VB.Menu File_Start 
  30.          Caption         =   "&Start"
  31.          Index           =   2
  32.          Shortcut        =   {F2}
  33.       End
  34.       Begin VB.Menu File_Stop 
  35.          Caption         =   "S&top"
  36.          Index           =   3
  37.       End
  38.       Begin VB.Menu File_Exit 
  39.          Caption         =   "E&xit"
  40.          Index           =   4
  41.       End
  42.    End
  43.    Begin VB.Menu Options 
  44.       Caption         =   "&Options"
  45.       Index           =   5
  46.       Begin VB.Menu Options_Explotions 
  47.          Caption         =   "&Explosions"
  48.          Index           =   6
  49.       End
  50.    End
  51. Attribute VB_Name = "Form1"
  52. Attribute VB_GlobalNameSpace = False
  53. Attribute VB_Creatable = False
  54. Attribute VB_PredeclaredId = True
  55. Attribute VB_Exposed = False
  56. Dim pieceon As Long
  57. Dim t1 As Single
  58. Option Explicit
  59. Private Sub File_Exit_Click(Index As Integer)
  60. Form1.Cls
  61. Unload Me
  62. End Sub
  63. Private Sub File_Start_Click(Index As Integer)
  64. File_Stop_Bit = 0
  65. Form1.Cls
  66. For Explosion_No = 1 To Explosions
  67.     SET_NEW_VALUES Explosion_No
  68. Next Explosion_No
  69. DoIt:
  70. COUNT_THE_COORDINATES
  71. 'CHECK_THE_COORDINATES
  72. ROTATE_PIECES
  73. DRAW_PIECES
  74. 'DoEvents: This is important
  75. 'If you don't put DoEvents in your main control routine
  76. 'You can't use any of the command buttons, textboxes, etc..
  77. 'Then you have to add it if you are programming games
  78. 'or something takes time like this
  79. DoEvents
  80. If File_Stop_Bit Then Exit Sub
  81. GoTo DoIt
  82. End Sub
  83. Private Sub File_Stop_Click(Index As Integer)
  84. Form1.Cls
  85. File_Stop_Bit = 1
  86. End Sub
  87. Private Sub Form_GotFocus()
  88. Label1.Caption = ""
  89. If Coming_From_Form_2 Then
  90.     File_Start_Click 1
  91. End If
  92. End Sub
  93. Private Sub Form_Load()
  94. Coming_From_Form_2 = 0
  95. 'This is the most important think
  96. Randomize Timer
  97. 'Set the default values
  98. DEFAULT_VALUES
  99. 'Take the screen width and height
  100. sw = Screen.Width
  101. sh = Screen.Height
  102. 'Half screen
  103. fw = sw / 2 'Set form width
  104. fh = sh / 2 'Set form Height
  105. 'Full screen
  106. 'fw = sw
  107. 'fh = sh
  108. '.Scalemode = 3, Sets the objects scale mode to pixels
  109. 'Enables to work with pixels while using the pset or line statements
  110. '1 pixel = 15 twips on 640*480
  111. Form1.ScaleMode = 3
  112. 'Put the form to the middle of the screen
  113. 'and set the form size
  114. '.Move method is faster than changing the left and top properties
  115. 'It is also easier to change the size of an object with .Move method
  116. Form1.Move sw / 2 - sw / 4, sh / 2 - sh / 4, fw, fh
  117. 'Fullscreen
  118. 'Form1.Move 0, 0, fw, fh
  119. End Sub
  120. Sub DEFAULT_VALUES()
  121. g = 0
  122. Explosions = 4
  123. Pieces(1) = 32: Pieces(2) = 64
  124. Pieces(3) = 32: Pieces(4) = 64
  125. Unit_x = 0.5: Unit_y = 0.5
  126. Unit_vx = 5: Unit_vy = 5
  127. End Sub
  128. Sub SET_NEW_VALUES(ExplosionNo As Single)
  129. Total_Count(ExplosionNo) = 0
  130. Explosion_x(ExplosionNo) = Rnd * fw / 15
  131. Explosion_y(ExplosionNo) = Rnd * (fh / 15 - 100)
  132. For Piece_No = 1 To Pieces(ExplosionNo)
  133.     Tmp_Str = ""
  134.     'One piece includes nine pixels
  135.     'The sort order makes the rotation easier
  136.     'But rotate only the first eight
  137.     'Because pixel nine is the center.
  138.     '   1 2 3
  139.     '   8 9 4
  140.     '   7 6 5
  141.     'Lets create the piece randomly:
  142.     For Counter = 1 To 9
  143.         Tmp_Str = Tmp_Str + LTrim$(Str$(Int(Rnd * 2)))
  144.     Next Counter
  145.     'For example,
  146.     'If the piece content is "110100101"
  147.     'it will look like this:
  148.     '   X X .
  149.     '   . X X
  150.     '   X . .
  151.     'Replace the content of the piece:
  152.     Piece_Content(ExplosionNo, Piece_No) = Tmp_Str
  153.     'To randomize the rotation frequency: (1,2,3 or 4)
  154.     'With this, every piece will have it's own frequency to turn
  155.     Rotation_Frq(ExplosionNo, Piece_No) = Int(1 + Int(Rnd * 4))
  156.     'To randomize the rotation: (0 or 1, 1 means clockwise)
  157.     Direction(ExplosionNo, Piece_No) = Int(Rnd * 2)
  158.     'Create the vertical and horizontal speed randomly
  159.     Piece_vx(ExplosionNo, Piece_No) = Unit_vx - (Rnd * 2 * Unit_vx) '(-Unit_vx,Unit_vx)
  160.     Piece_vy(ExplosionNo, Piece_No) = Unit_vy - (Rnd * 2 * Unit_vy) '(-Unit_vy,Unit_vy)
  161.     Piece_x(ExplosionNo, Piece_No) = Explosion_x(ExplosionNo)
  162.     Piece_y(ExplosionNo, Piece_No) = Explosion_y(ExplosionNo)
  163.     Piece_dx(ExplosionNo, Piece_No) = Piece_x(ExplosionNo, Piece_No)
  164.     Piece_dy(ExplosionNo, Piece_No) = Piece_y(ExplosionNo, Piece_No)
  165. Next Piece_No
  166. 'The values for drawing by the content strings
  167. Dr_Cont_x1(1) = -4 * Unit_x: Dr_Cont_y1(1) = -4 * Unit_y
  168. Dr_Cont_x2(1) = -2 * Unit_x: Dr_Cont_y2(1) = -2 * Unit_y
  169. Dr_Cont_x1(2) = -1 * Unit_x: Dr_Cont_y1(2) = -4 * Unit_y
  170. Dr_Cont_x2(2) = 1 * Unit_x: Dr_Cont_y2(2) = -2 * Unit_y
  171. Dr_Cont_x1(3) = 2 * Unit_x: Dr_Cont_y1(3) = -4 * Unit_y
  172. Dr_Cont_x2(3) = 4 * Unit_x: Dr_Cont_y2(3) = -2 * Unit_y
  173. Dr_Cont_x1(4) = 2 * Unit_x: Dr_Cont_y1(4) = -1 * Unit_y
  174. Dr_Cont_x2(4) = 4 * Unit_x: Dr_Cont_y2(4) = 1 * Unit_y
  175. Dr_Cont_x1(5) = 2 * Unit_x: Dr_Cont_y1(5) = 2 * Unit_y
  176. Dr_Cont_x2(5) = 4 * Unit_x: Dr_Cont_y2(5) = 4 * Unit_y
  177. Dr_Cont_x1(6) = -1 * Unit_x: Dr_Cont_y1(6) = 2 * Unit_y
  178. Dr_Cont_x2(6) = 1 * Unit_x: Dr_Cont_y2(6) = 4 * Unit_y
  179. Dr_Cont_x1(7) = -4 * Unit_x: Dr_Cont_y1(7) = 2 * Unit_y
  180. Dr_Cont_x2(7) = -2 * Unit_x: Dr_Cont_y2(7) = 4 * Unit_y
  181. Dr_Cont_x1(8) = -4 * Unit_x: Dr_Cont_y1(8) = -1 * Unit_y
  182. Dr_Cont_x2(8) = -2 * Unit_x: Dr_Cont_y2(8) = 1 * Unit_y
  183. Dr_Cont_x1(9) = -1 * Unit_x: Dr_Cont_y1(9) = -1 * Unit_y
  184. Dr_Cont_x2(9) = 1 * Unit_x: Dr_Cont_y2(9) = 1 * Unit_y
  185. 'As you see, number nine is the center
  186. End Sub
  187. Sub ROTATE_PIECES()
  188. For Explosion_No = 1 To Explosions
  189.     For Piece_No = 1 To Pieces(Explosion_No)
  190.         If Total_Count(Explosion_No) Mod Rotation_Frq(Explosion_No, Piece_No) = 0 Then
  191.             'Take the first 8 characters of the piece:
  192.             Tmp_Str = Left$(Piece_Content(Explosion_No, Piece_No), 8)
  193.             'if the direction is clockwise:
  194.             If Direction(Explosion_No, Piece_No) = 1 Then
  195.                 'Add the last pixel to the start, and then take the first eight
  196.                 'So we have the piece turned
  197.                 Tmp_Str = Left$(Right$(Tmp_Str, 1) + Tmp_Str, 8)
  198.             'if not:
  199.             Else
  200.                 'Add the first pixel to the end, and then take the last eight
  201.                 'So we have the piece turned again
  202.                 Tmp_Str = Right$(Tmp_Str + Left$(Tmp_Str, 1), 8)
  203.             End If
  204.             'Replace the piece
  205.             'Don't forget to add the center piece
  206.             Piece_Content(Explosion_No, Piece_No) = Tmp_Str + Right$(Piece_Content(Explosion_No, Piece_No), 1)
  207.         End If
  208.     Next Piece_No
  209. Next Explosion_No
  210. End Sub
  211. Sub COUNT_THE_COORDINATES()
  212. For Explosion_No = 1 To Explosions
  213.     'Add 1 to total counts
  214.     Total_Count(Explosion_No) = Total_Count(Explosion_No) + 1
  215.     For Piece_No = 1 To Pieces(Explosion_No)
  216.         Piece_dx(Explosion_No, Piece_No) = Piece_x(Explosion_No, Piece_No)
  217.         Piece_dy(Explosion_No, Piece_No) = Piece_y(Explosion_No, Piece_No)
  218.         Piece_x(Explosion_No, Piece_No) = Piece_x(Explosion_No, Piece_No) + Piece_vx(Explosion_No, Piece_No)
  219.         Piece_vy(Explosion_No, Piece_No) = Piece_vy(Explosion_No, Piece_No) + g
  220.         Piece_y(Explosion_No, Piece_No) = Piece_y(Explosion_No, Piece_No) + Piece_vy(Explosion_No, Piece_No)
  221.     Next Piece_No
  222.     If Total_Count(Explosion_No) >= 75 Then
  223.         If Rnd < 0.15 Then
  224.             CLEAR_PIECES Explosion_No, 0, 1
  225.             SET_NEW_VALUES Explosion_No
  226.         End If
  227.     End If
  228. Next Explosion_No
  229. End Sub
  230. Sub CHECK_THE_COORDINATES()
  231. For Explosion_No = 1 To Explosions
  232.     For Piece_No = 1 To Pieces(Explosion_No)
  233.         'Check the pieces hitting the walls
  234.         If Piece_x(Explosion_No, Piece_No) >= fw / 15 Then
  235.             Piece_x(Explosion_No, Piece_No) = fw / 15 - 2
  236.             Piece_vx(Explosion_No, Piece_No) = -Piece_vx(Explosion_No, Piece_No)
  237.         ElseIf Piece_x(Explosion_No, Piece_No) <= 0 Then
  238.             Piece_x(Explosion_No, Piece_No) = 1
  239.             Piece_vx(Explosion_No, Piece_No) = -Piece_vx(Explosion_No, Piece_No)
  240.         End If
  241.         If Piece_y(Explosion_No, Piece_No) >= fh / 15 - 60 Then
  242.             Piece_y(Explosion_No, Piece_No) = fh / 15 - 62
  243.             Piece_vy(Explosion_No, Piece_No) = -Piece_vy(Explosion_No, Piece_No) / 2
  244.         ElseIf Piece_y(Explosion_No, Piece_No) <= 0 Then
  245.             Piece_y(Explosion_No, Piece_No) = 1
  246.             Piece_vy(Explosion_No, Piece_No) = -Piece_vy(Explosion_No, Piece_No) / 2
  247.         End If
  248.     Next Piece_No
  249. Next Explosion_No
  250. End Sub
  251. Sub DRAW_PIECES()
  252. pieceon = pieceon + 1
  253. If Timer - t1 > 1 Then
  254.     Label1.Caption = "fps: " + Str$(pieceon)
  255.     pieceon = 0
  256.     t1 = Timer
  257. End If
  258. 'If you want, you can use the cls command for clearing the form
  259. 'form1.cls
  260. For Explosion_No = 1 To Explosions
  261.     For Piece_No = 1 To Pieces(Explosion_No)
  262.         'First, delete the existing by drawing a black box
  263.         'It looks better than clear the form with cls
  264.         Form1.Line (Piece_dx(Explosion_No, Piece_No) - 4 * Unit_x, Piece_dy(Explosion_No, Piece_No) - 4 * Unit_y)-(Piece_dx(Explosion_No, Piece_No) + 4 * Unit_y, Piece_dy(Explosion_No, Piece_No) + 4 * Unit_y), QBColor(0), BF
  265.         'Then set the new one
  266.         For Counter = 1 To 9
  267.             If Mid$(Piece_Content(Explosion_No, Piece_No), Counter, 1) = "1" Then
  268.                 Form1.PSet (Piece_x(Explosion_No, Piece_No) + Dr_Cont_x1(Counter), Piece_y(Explosion_No, Piece_No) + Dr_Cont_y1(Counter)), QBColor(14)
  269.             End If
  270.         Next Counter
  271.     Next Piece_No
  272. Next Explosion_No
  273. End Sub
  274. Sub CLEAR_PIECES(ExplosionNo As Single, PieceNo As Single, All As Single)
  275. 'If the user wants to clear all pieces
  276. 'of the explosion:
  277. If All = 1 Then
  278.     For Piece_No = 1 To Pieces(ExplosionNo)
  279.         Form1.Line (Piece_dx(ExplosionNo, Piece_No) - 4 * Unit_x, Piece_dy(ExplosionNo, Piece_No) - 4 * Unit_y)-(Piece_dx(ExplosionNo, Piece_No) + 4 * Unit_y, Piece_dy(ExplosionNo, Piece_No) + 4 * Unit_y), QBColor(0), BF
  280.     Next Piece_No
  281. 'If the user wants to clear only one piece
  282.     Form1.Line (Piece_dx(ExplosionNo, Piece_No) - 4 * Unit_x, Piece_dy(ExplosionNo, Piece_No) - 4 * Unit_y)-(Piece_dx(ExplosionNo, Piece_No) + 4 * Unit_y, Piece_dy(ExplosionNo, Piece_No) + 4 * Unit_y), QBColor(0), BF
  283. End If
  284. End Sub
  285. Private Sub Options_Explotions_Click(Index As Integer)
  286. Form2.Show
  287. End Sub
  288.